<?php
namespace Admin\Controller;
use Common\Model\FollowModel;

use Think\Controller;
use Admin\Controller\AdminController; 
use Think\Verify;

class FuturesRechargeController extends AdminController{
	/*页面加载*/
	public function index(){
		/*状态查询*/
		if($_REQUEST['status']){
			if($_REQUEST['status']==1){
				$sql['a.is_pay']=array('eq',1);
				$status=1;
			}elseif($_REQUEST['status']==2){
				$sql['a.is_pay']=array('eq',0);
				$status=2;
			}else{
				$status=-1;
			}
		}
		else{
			$status=-1;
		}
		/*用户查询*/
		if($_GET['uname']){
			$sql['b.nickname']=array('like',"%".trim($_REQUEST['uname'])."%");
		}
		if($_GET['mobile']){
			$sql['b.mobile']=array('like',"%".trim($_REQUEST['mobile'])."%");
		}
		/*生成时间查询*/
		$start_time=I('get.start_time');
		if($start_time){
			$sql['a.create_time']=array('egt',strtotime($start_time));
			$this->assign('start_time',$start_time);
		}
		$end_time=I('get.end_time');
		if($end_time){
			$end_time=strtotime($end_time)+86400;
			$sql['_string']='a.create_time <='.$end_time;
		}
		//分页查询
		$count = M('Futures_recharge')->alias('a')->join("wp_follow b on a.user_id = b.id")->where($sql)->count();//print_r($count);die;
		$Page = new \Think\Page($count,10);
		if($count>10){
			$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
		}
		$show = $Page->show();
		$list = M('Futures_recharge')->alias('a')->join("wp_follow b on a.user_id = b.id")->where($sql)->where($sql)->order('a.id desc')->limit($Page->firstRow.','.$Page->listRows)->field('a.*,b.nickname as uname,b.mobile')->select();
		$money_data = M('Futures_recharge')->alias('a')->join("wp_follow b on a.user_id = b.id")->field('a.*,sum(a.money) as topmoney')->where($sql)->group('a.is_pay')->select();
		for($i = 0;$i<count($money_data);$i++){
			$money_data[$i]['topmoney'] = round($money_data[$i]['topmoney'],2);
		}
		$this->assign('money_data',$money_data);
		$this->assign('status',$status);
		$this->assign('_page',$show);//
		$this->assign('list',$list);
		$this->display();
	}
}